package com.codedancer.campus.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.po.UserFollow;
import com.codedancer.campus.qo.user.UserFanPageSearchQo;
import com.codedancer.campus.qo.user.UserFollowPageSearchQo;
import org.apache.ibatis.annotations.Param;

public interface UserFollowMapper extends BaseMapper<UserFollow> {

    /**
     * 取消关注用户
     *
     * @param uuid
     * @param currentLoginUuid
     */
    default void cancelFollow(String uuid, String currentLoginUuid) {
        LambdaQueryWrapper<UserFollow> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserFollow::getFollowedUserUuid, uuid);
        lambdaQueryWrapper.eq(UserFollow::getFollowUserUuid, currentLoginUuid);
        delete(lambdaQueryWrapper);
    }

    /**
     * 判断是否已经关注
     *
     * @param uuid
     * @param currentLoginUuid
     * @return
     */
    default boolean isFollow(String uuid, String currentLoginUuid) {
        LambdaQueryWrapper<UserFollow> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserFollow::getFollowedUserUuid, uuid);
        lambdaQueryWrapper.eq(UserFollow::getFollowUserUuid, currentLoginUuid);
        return selectCount(lambdaQueryWrapper) > 0;
    }

    /**
     * 分页查询关注用户
     *
     * @param userFollowPage
     * @param userFollowPageSearchQo
     * @return
     */
    IPage<UserFollow> pageFollow(Page<UserFollow> userFollowPage, @Param("userFollowPageSearchQo") UserFollowPageSearchQo userFollowPageSearchQo);

    /**
     * 分页查询关注粉丝(关注我的人)
     *
     * @param userFollowPage
     * @param userFanPageSearchQo
     * @return
     */
    IPage<UserFollow> pageFan(Page<UserFollow> userFollowPage, @Param("userFanPageSearchQo") UserFanPageSearchQo userFanPageSearchQo);
}
